package com.usian.listener;

import com.alibaba.fastjson.JSON;
import com.usian.pojo.User;
import org.apache.kafka.clients.consumer.ConsumerRecord;
import org.springframework.kafka.annotation.KafkaListener;
import org.springframework.stereotype.Component;

import java.util.Optional;


@Component
public class HelloListener {
    @KafkaListener(topics = {"kafka-hello"})
    public void message(ConsumerRecord<?,?> record){
        Optional<? extends ConsumerRecord<?,?>> optional=Optional.ofNullable(record);
        if (optional.isPresent()){
            String value = (String) record.value();
            System.out.println(JSON.parseObject(value, User.class));
        }
    }
}
